package de.koller.worlders.engine.entity.mo;

import de.koller.oceanFramework.tree.Mother;
import de.koller.worlders.WSea;
import de.koller.worlders.engine.WInputGL;
import org.lwjgl.input.Keyboard;

public class PlayerSteeringC extends WSea {
	
	@Mother private Player player;

	@Override
	protected void init() {
		super.init();
		
		wroot.getEntityContainer().setShowCrosshair( false );
	}
	
	@Override
	protected void update( int elapsedTime ) {
		super.update( elapsedTime );
		
		if( player.isDeath() )
			return;
		
		if( wroot.getDebug().isActive() || wroot.getGui().getConsoleInput().isOpen() )
			return;
		
		walking();
		jumping();
		reseting();
		normiring();
	}
	
	private void normiring() {
		WInputGL in = wroot.getInput();
		
		if( in.isKeyDown( Keyboard.KEY_DOWN ) || in.isKeyDown( Keyboard.KEY_S ) )
			player.norming();
	}
	
	private void walking() {
		WInputGL in = wroot.getInput();
		
		int a = 0;
		a += ( in.isKeyDown( Keyboard.KEY_D ) || in.isKeyDown( Keyboard.KEY_RIGHT ) ) ?  1 : 0;
		a += ( in.isKeyDown( Keyboard.KEY_A ) || in.isKeyDown( Keyboard.KEY_LEFT  ) ) ? -1 : 0;
		
		player.walk( a );
	}
	
	private void jumping() {
		WInputGL in = wroot.getInput();
		
		if( in.isKeyDown(Keyboard.KEY_SPACE ) || in.isKeyDown( Keyboard.KEY_W ) )
			player.jump();
	}
	
	private void reseting() {
		WInputGL in = wroot.getInput();
		
		if( !in.isKeyPressed( Keyboard.KEY_R ) )
			return;
		
		player.reset();
	}
	
}
